enum Method { post, get }

enum HttpResponseType { json, stream, plain, bytes }

enum HttpRequestLoginPolicy {
  /// 判断用户登录，不管判断结果如何，继续服务（如果登录，服务带登录信息到服务端）
  soft,

  /// 判断用户登录，已登，服务继续。未登，弹出登录
  needLogin
}

// TODO: 暂未实现
enum HttpCacheType {
  /// 不缓存
  none,

  /// 本地数据库
  localDB,

  /// 本地简单存储
  localKV,

  /// host缓存
  api,
}

abstract class HttpApi {
  /// base url
  String? get baseUrl => null;

  /// 请求头
  Map<String, dynamic>? get header => null;

  /// 接口地址
  String path();

  /// 参数
  Map<String, dynamic> params();

  /// 是否显示loading
  bool get showLoading => false;

  /// 请求方式
  Method get method => Method.post;

  /// 鉴权
  HttpRequestLoginPolicy get loginPolicy => HttpRequestLoginPolicy.soft;

  /// 缓存策略
  HttpCacheType get cache => HttpCacheType.none;

  /// 响应体类型
  HttpResponseType get responseType => HttpResponseType.json;
}

class BaseApi implements HttpApi {
  @override
  String? get baseUrl => null;

  @override
  HttpCacheType get cache => HttpCacheType.none;

  @override
  Map<String, dynamic>? get header => null;

  @override
  HttpRequestLoginPolicy get loginPolicy => HttpRequestLoginPolicy.soft;

  @override
  Method get method => Method.post;

  @override
  Map<String, dynamic> params() {
    return <String, dynamic>{};
  }

  @override
  HttpResponseType get responseType => HttpResponseType.json;

  @override
  String path() {
    return "";
  }

  @override
  bool get showLoading => false;
}
